import React from "react";
import request from '../../api/request'
import { Button, Space, Toast } from 'antd-mobile'
import {
  Form,
  Input,
} from "antd-mobile";
import { data, useNavigate } from "react-router-dom";
function Index() {
    let nav=useNavigate()
    const onFinish = async(values) => {
        let res=await request.post('/xx/login',values)

        console.log(res)
        let {code,message}=res.data
        if(code===10000){
            Toast.show({

                icon: "success",
                content: message,
                
              });
              localStorage.setItem('token',data.token)
              localStorage.setItem('username',res.username)
              nav('/')
            } else {
              Toast.show({
                icon: "fail",
                content: message,
              });
        }
      }
  return (
    <div>
      <Form
      onFinish={onFinish}
        layout="horizontal"
        footer={
          <Button block type="submit" color="primary" size="large">
            提交
          </Button>
        }
      >
        <Form.Item
          name="username"
          label="账号"
          rules={[{ required: true, message: "账号不能为空" }]}
        >
          <Input onChange={console.log} placeholder="请输入账号" />
        </Form.Item>
        <Form.Item
          name="password"
          label="密码"
          rules={[{ required: true, message: "密码不能为空" }]}
        >
          <Input onChange={console.log} placeholder="请输入密码" />
        </Form.Item>
      </Form>
    </div>
  );
}

export default Index;
